<?php


class MarkTable extends Doctrine_Table
{
    
    public static function getInstance()
    {
        return Doctrine_Core::getTable('Mark');
    }
    
    public static function queryWithDistinctListType($id){
    	return self::getInstance()->createQuery('m')->select('m.list_type')
    	->addWhere('m.id_annoset = ?', $id)
  		->groupBy('m.list_type');
  		//->having('m.list_type != ?', 'tok') avoid tok to be delimiter
    }
    
    public static function queryWithOutDelimiter($id, $delimiter){
    	return self::getInstance()->createQuery('m')->leftJoin('m.Annoset a')
    		->addWhere('m.id_annoset = ?', $id);
    		//->where('m.list_type != ?', $delimiter) avoid delimiters to be part of marks to show
    }
    
    public static function queryWithDelimiter($id, $delimiter){
    	return self::getInstance()->createQuery('m')->leftJoin('m.Annoset a')->where('m.list_type = ?', $delimiter)
    		->addWhere('m.id_annoset = ?', $id);
    }
    
    public static function getLayers($id){
    	return self::getInstance()->createQuery('m')->select('m.list_type')
				->where('m.id_annoset = ?', $id)->groupBy('m.list_type ASC');
    }
    
	public static function getMaxId(){
		$record = self::getInstance()->createQuery('m')->select('max(m.id)')->execute();
		return $record[0]->getMax();
	}
    
}